<template>
  <detail-drawer
    v-model:visible="detailVisible"
    :data="detailData"
    :get-container="getContainer"
    :title="t('aiot.comment.visitDetail')"
  >
  </detail-drawer>
</template>
<script setup lang="ts">
import { ref, watch } from "vue";
import type { DetailItem } from "/@/types/components";
import { useI18n } from "/@/locales/useI18n";
import { getOrderVisitDetail, getComplainVisitDetail } from "/@/api/aiot/commentManage";

const props = withDefaults(
  defineProps<{
    //是否获取投诉单回访信息，否的话则是获取服务回访详细信息
    isComplain?: boolean;
    getDetailId: string | null;
    getContainer?: string;
  }>(),
  {
    getContainer: "#home-content",
  }
);
const emits = defineEmits(["update:getDetailId"]);
watch(
  () => props.getDetailId,
  async (v) => {
    if (!v) return;
    emits("update:getDetailId", null);
    const data = props.isComplain ? await getComplainVisitDetail(v) : await getOrderVisitDetail(v);
    if (data) {
      detailVisible.value = true;
      detailData.value = [
        {
          label: t("aiot.comment.visitCode"),
          value: data.visitRecordCode,
        },
        {
          label: t("aiot.serviceOrder.visitRecordTitle"),
          value: data.visitRecordTitle,
        },
        {
          label: t("aiot.comment.visitType"),
          value: t("baseData.visitType." + data.workOrderVisitRecordType),
        },
        {
          label: t("aiot.comment.visitUser"),
          value: data.visitRecordUserName,
        },
        {
          label: t("aiot.comment.visitTarget"),
          value: data.visitRecordCustomer + (data.visitRecordCustomerPhone ? `(${data.visitRecordCustomerPhone})` : ""),
        },
        {
          label: t("aiot.serviceOrder.visitRecordTime"),
          value: data.visitRecordTime,
        },
        {
          label: t("aiot.serviceOrder.visitRecordContent"),
          value: data.visitRecordContent,
        },
        {
          label: "客户意见",
          value: data.visitRecordSuggestion,
        },
      ];
    }
  }
);

const { t } = useI18n();
const detailVisible = ref(false);
const detailData = ref<DetailItem[]>([]);
</script>
